from typing import List

# 减少不必要的字符串比较
class Solution:

    def __init__(self):
        self.wss = {}

    def maxProduct(self, words: List[str]) -> int:
        words.sort(key = lambda it:len(it), reverse=True)
        ws = [set(w) for w in words]
        wlen = len(words)
        r = 0
        for i in range(wlen - 1):
            wi = words[i]
            leni = len(wi)
            for j in range(i + 1, wlen):
                wj = words[j]
                p = leni * len(wj)
                if p > r and len(ws[i] & ws[j]) == 0:
                    print('x')
                    r = p
        return r

solu = Solution()
result = solu.maxProduct(["abcw", "baz", "foo", "bar", "xtfn", "abcdef"])
print(result)
